/**
 * @Author：ming
 * @Date：2023/10/25 2:10 PM
 * @Filename：LC144
 */

import java.util.ArrayList;
import java.util.List;

/**
 * @author ming
 */
public class LC145 {
    public List<Integer> preorderTraversal(TreeNode root) {

        List<Integer> list = new ArrayList<>();
        preOrder(root,list);
        return list;
    }

    public static void preOrder(TreeNode treeNode,List<Integer> list){
        if(treeNode==null){
            return;
        }
        preOrder(treeNode.left,list);
        preOrder(treeNode.right,list);
        list.add(treeNode.val);
    }

}
